package com.eco.fanliapp.utils;

import com.eco.fanliapp.common.constant.ApiEnum;

import java.util.Map;

/**
 * API请求方法
 * @author xiaoxx
 *
 */
public class ApiUtils {

	/**
	 * 好单库
	 * get请求
	 * @param type 模块名称
	 * @param param 参数
	 * @return
	 */
	public static String getData(String type,Map<String, Object> param){
		StringBuilder builder = new StringBuilder();
		builder.append(ApiEnum.URL);
		builder.append(type).append("/");
		builder.append("apikey/").append(ApiEnum.HDK_APIKEY).append("/");
		return HttpUtils.sendGet(builder.toString(), param);
	}
	
	/**
	 * 好单库
	 * get请求
	 * @param type 模块名称
	 * @param param 参数
	 * @return
	 */
	public static String getData(String type,String param){
		StringBuilder builder = new StringBuilder();
		builder.append(ApiEnum.URL);
		builder.append(type).append("/");
		builder.append("apikey/").append(ApiEnum.HDK_APIKEY).append("/");
		return HttpUtils.sendGet(builder.toString(), param);
	}
	
	/**
	 * 好单库
	 * post请求
	 * @param type 模块名称
	 * @param param 参数
	 * @return
	 */
	public static String postData(String type,String param){
		StringBuilder builder = new StringBuilder();
		builder.append(ApiEnum.URL);
		builder.append(type).append("?");
		builder.append("apikey=").append(ApiEnum.HDK_APIKEY).append("&");
		return HttpUtils.sendPost2(builder.toString(), param);
	}
	
	/**
	 * Eco
	 * get请求
	 * @param type 模块名称
	 * @param param 参数
	 * @return
	 */
	public static String getEcoData(String type,String param){
		StringBuilder builder = new StringBuilder();
		builder.append(ApiEnum.ECO_URL);
		if("privilege".equals(type)){
			builder.append(type).append("/");
		}else{
			builder.append(type).append("?");
		}
		return HttpUtils.sendGet(builder.toString(), param);
	}

	/**
	 * Eco
	 * get请求
	 * @param type 模块名称
	 * @param param 参数
	 * @return
	 */
	public static String getEcoDataO(String type,String param){
		StringBuilder builder = new StringBuilder();
		builder.append(ApiEnum.ECO_URL);
		if("privilege".equals(type)){
			builder.append(type).append("/");
		}else{
			builder.append(type).append("?");
		}
		return HttpUtils.sendGetEcoTKL(builder.toString(), param);
	}
	
	/**
	 * Eco
	 * post请求
	 * @param type 模块名称
	 * @param param 参数
	 * @return
	 */
	public static String postEcoData(String type,String param){
		StringBuilder builder = new StringBuilder();
		builder.append(ApiEnum.ECO_URL);
		builder.append(type).append("?");
		return HttpUtils.sendPost2(builder.toString(), param);
	}

	/**
	 * Eco超级搜索请求
	 * post请求
	 * @param type 模块名称
	 * @param param 参数
	 * @return
	 */
	public static String postSuperTitle(String type,String param){
		StringBuilder builder = new StringBuilder();
		builder.append(ApiEnum.ECO_URL);
		builder.append(type).append("?");
		return HttpUtils.getRestTemplate(builder.toString(), param);
	}
	
	/**
	 * 维意
	 * get请求
	 * @param type 模块名称
	 * @param param 参数
	 * @return
	 */
	public static String getWYData(String type,String param){
		StringBuilder builder = new StringBuilder();
		builder.append(ApiEnum.WEIYI_URL);
		builder.append(type).append("?");
		builder.append("vekey=").append(ApiEnum.WEIYI_APIKEY);
		return HttpUtils.sendGet(builder.toString(), param);
	}
	
	/**
	 * 维意
	 * post请求
	 * @param type 模块名称
	 * @param param 参数
	 * @return
	 * http://apipro.vephp.com/itemdetail?vekey=V00001043Y60238823&para=587697102297&shoptype=C&moreinfo=1
	 */
	public static String postWYData(String type,String param){
		StringBuilder builder = new StringBuilder();
		builder.append(ApiEnum.WEIYI_URL);
		builder.append(type).append("?");
		builder.append("vekey=").append(ApiEnum.WEIYI_APIKEY);
		return HttpUtils.sendPost2(builder.toString(), param);
	}


	/**
	 * 好单库
	 * get请求
	 * @param param 参数
	 * @return
	 */
	public static String getDataHistory(Map<String, Object> param){
		StringBuilder builder = new StringBuilder();
		builder.append("https://www.haodanku.com").append("/");
		builder.append("detail").append("/");
		builder.append("get_history_content").append("/");
		return HttpUtils.sendGet(builder.toString(), param);
	}
}
